#include <iostream>
#include <cstring>
using namespace std;

class String
{
    char *str;

public:
    String(const char *p)
    {
        cout << "String(const char *p) 构造函数运行啦" << endl;
        int len = std::strlen(p);
        str = new char[len + 1];
        for (int i = 0; i < len; i++)
        {
            str[i] = p[i];
        }
    }
    String(int len, char c)
    {
        cout << "String(int len, char c) 构造函数运行啦" << endl;
        str = new char[len + 1];
        for (int i = 0; i < len; i++)
        {
            str[i] = c;
        }
        str[len] = '\0';
    }
    // 无参构造函数
    String()
    {
        cout << "String() 无参构造函数运行啦" << endl;
        str = new char[1]{'\0'};
    }
    ~String()
    {
        cout << "做一些清理工作" << endl;
        delete[] str;
    }
};
int main()
{
    String s1("111");
    String s2(10, '1');
    // 无参构造函数的初始化,不能写括号
    String s3;
    // String s3();
}
